package com.jswlw.common.utils;

import java.util.List;

/**
 * 模板处理规则
 */
public class TempleteUtils {

    /**
     * 解析模板
     *
     * @param tpl
     * @param params
     * @return
     */
    public static String parse(String tpl, List<String> params) {
        for (int i = 0; i < params.size(); i++) {
            tpl = tpl.replaceAll("\\{" + i + "\\}", params.get(i));
        }
        return tpl;
    }

    /**
     * 解析模板
     *
     * @param tpl
     * @param
     * @return
     */
    public static int parseParamsCount(String tpl) {
        int num = 0;
        String[] array = tpl.split("\\{");
        if (array != null) {
            num = (array.length - 1);
        }
        return num;
    }
}
